home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cc03.arc / LINKED.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-03-15  |  720 b   |  33 lines

  1. /* copyright (c) 1982 by the Toolsmith */
  2.  
  3. struct linked_list {
  4.         struct linked_list *link;
  5. };
  6.  
  7. /* reverse - invert order of a linked list */
  8.  
  9. struct linked_list *reverse(this)
  10. register struct linked_list *this;
  11. {
  12.         register struct linked_list *next, *previous;
  13.  
  14.         for (previous = NULL; this != NULL; previous = this, this = next) {
  15.                 next = this->link;
  16.                 this->link = previous;
  17.         }
  18.  
  19.         return previous;
  20. }
  21.  
  22. /* insert - add an "n" byte element to fron of "list"  */
  23.  
  24. struct linked_list *insert(n, list)
  25. unsigned n;
  26. struct linked_list *list;
  27. {
  28.         extern char *alloc();
  29.  
  30.         return (struct linked_list *) alloc(n, list);
  31. }
  32.  
  33.